// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessible from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;
int i,j,k,x,y;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
beginstate START_SCEN_STATE;
	//pre-calculate exit point locations
	k = 0;
	while(k<25){
		if((k%5) == 0){
			if((k%10) == 0)
				i=8;
			else
				i=4;
			j=(((k / 5) + 1) * 12) - 6;
		}
		set_flag(5,k,i);
		set_flag(6,k,j);
		i = i + 12;
		k = k + 1;
	}
	set_flag(0,0,1);
	if((party_size() > 1) || (char_ok(0) != 1))
		message_dialog("WARNING: This scenario is intended to be played using a singleton party with the only character in the first slot. ","No guarantee is made that this scenario will behave properly with other party configurations.");
	message_dialog("After a few hours travel from Bramsford, you find the small, nearly buried cave entrance that must lead into the dungeon. You make your way in and descend a few hundred yards, and come to a room that was clearly built deliberately.","You've found the dungeon all right; now all you have to do is get out alive again. ");
break;

// This state is called every tick wherever the party is in the scenario.
beginstate START_STATE;
	get_flag(11,10);
	get_flag(11,11);
	get_flag(11,12);
	get_flag(11,13);
	if((get_current_tick() % 150) == 0)
		heal_char(0,1); //a little touch of extra healing
	if(get_flag(0,5) > 0){ //in identification mode
		set_flag(0,5,get_flag(0,5) - 1); //decrement number of turns remaining
		if(get_flag(0,5) == 0){ //end identification mode
			alter_stat(0, 13, -1 * get_flag(0,6));
			alter_stat(0, 2, -1 * get_flag(0,7));
		}
	}
	if(get_energy(0) < 0) //fix for shade essence causing negative energy
		change_char_energy(0,-1 * get_energy(0));
break;

//spell teaching scrolls
beginstate 10; //Bolt of Fire
	j = 1;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Bolt of Fire spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,0,1);
		take_item(472);
	}
break;

beginstate 11; //Healing
	j = 1;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Healing spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,0,1);
		take_item(473);
	}
break;

beginstate 12; //Curing
	j = 1;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Curing spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,1,1);
		take_item(474);
	}
break;

beginstate 13; //Call Beast
	j = 2;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Call Beast spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,2,1);
		take_item(475);
	}
break;

beginstate 14; //War Blessing
	j = 1;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the War Blessing spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,2,1);
		take_item(476);
	}
break;

beginstate 15; //Spray Acid
	j = 2;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Spray Acid spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,3,1);
		take_item(477);
	}
break;

beginstate 16; //Haste
	j = 3;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Haste spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,4,1);
		take_item(478);
	}
break;

beginstate 17; //Repel Spirit
	j = 3;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Repel Spirit spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,4,1);
		take_item(479);
	}
break;

beginstate 18; //Slow
	j = 4;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Slow spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,5,1);
		take_item(480);
	}
break;

beginstate 19; //Smite
	j = 4;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Smite spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,5,1);
		take_item(481);
	}
break;

beginstate 20; //Summon Shade
	j = 5;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Summon Shade spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,6,1);
		take_item(482);
	}
break;

beginstate 21; //ice Lances
	j = 5;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Ice Lances spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,6,1);
		take_item(483);
	}
break;

beginstate 22; //Enduring Barrier
	j = 5;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Enduring Barrier spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,7,1);
		take_item(484);
	}
break;

beginstate 23; //Lightning Spray
	j = 8;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Lightning Spray spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,10,1);
		take_item(485);
	}
break;

beginstate 24; //Divine Fire
	j = 10;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Divine Fire spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,13,1);
		take_item(486);
	}
break;

beginstate 25; //Summon Aid
	j = 12;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Summon Aid spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,14,1);
		take_item(487);
	}
break;

beginstate 26; //Fireblast
	j = 14;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Fireblast spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,16,1);
		take_item(488);
	}
break;

beginstate 27; //Divine Retribution
	j = 15;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Divine Retribution spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,17,1);
		take_item(489);
	}
break;

beginstate 28; //Arcane Blow
	j = 17;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Arcane Blow spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,19,1);
		take_item(490);
	}
break;

beginstate 29; //Divine Restoration
	j = 16;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Divine Restoration spell. ",0);
	if(get_stat(0,12) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Priest spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,12) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,1,18,1);
		take_item(491);
	}
break;

beginstate 30; //Arcane Shield
	j = 16;
	reset_dialog();
	add_dialog_str(0,"This scroll indicates that it is intended to teach about the Arcane Shield spell. ",0);
	if(get_stat(0,11) < j)
		add_dialog_str(1,"You glance over the scroll, but realize that it looks much too complicated for you. You just don't have the familiarity with Mage spells to handle this yet. ",5);
	add_dialog_choice(0,"Save this for later");
	if(get_stat(0,11) >= j)
		add_dialog_choice(1,"Study it now");
	i = run_dialog(0);
	if(i == 2){
		change_spell_level(0,0,18,1);
		take_item(492);
	}
break;
//end of spell teaching scrolls

beginstate 31; //identification scroll
	if(party_has_status(19)){
		print_str_color("You are already identifying items.",2);
		end();
	}
	take_item(493);
	set_char_status(0,19,3,1,1);
	set_flag(0,6,80 - get_stat(0,13));
	alter_stat(0,13, get_flag(0,6));
	set_flag(0,7,50 - get_stat(0,2));
	alter_stat(0,2, get_flag(0,7));
	set_flag(0,5,3);
	print_str_color("Pick up an item and put in in your inventory",2);
	print_str_color("	to identify all of your items.",2);
break;

beginstate 32; //lucky crystal
	print_str("You polish the crystal. It shines in the faint light.");
	if((get_flag(10,4) == 1) || (get_flag(10,5) == 1) || (get_flag(10,6) == 1) || (get_flag(10,7) == 1))
		print_str("The back of your neck prickles.");
	if(get_flag(10,9) == 1 && get_flag(10,8) == 0)
		print_str("You feel a sudden itch on your nose.");
	j = 0;
	i = 6;
	while(i<120){
		if(char_ok(i) && ((creature_type(i) == 47) || (creature_type(i) == 49))){
			j = 1;
			i = 1000; //break out
		}
		i = i + 1;
	}
	if(j==1)
		print_str("You feel a chill breeze blow over you.");
	if((get_flag(10,0) == 1) || (get_flag(10,1) == 1) || (get_flag(10,2) == 1) || (get_flag(10,3) == 1))
		print_str("Your throat feels parched.");
break;

beginstate 33; //wand of devastation
	put_straight_zap(char_loc_x(who_used_custom_item()),char_loc_y(who_used_custom_item()),char_loc_x(who_is_custom_item_target()),char_loc_y(who_is_custom_item_target()),6);
	put_jagged_zap(char_loc_x(who_used_custom_item()),char_loc_y(who_used_custom_item()),char_loc_x(who_is_custom_item_target()),char_loc_y(who_is_custom_item_target()),4);
	run_animation_sound(53);
	i = 0;
	while(i < 7){
		damage_char(who_is_custom_item_target(),get_ran(1,40,50),i);
		i = i + 1;
	}
break;

beginstate 40; //reveal secret passage
	if(get_flag(10,8) == 0){
		if(((get_flag(0,10) + 420) >= 421) && ((get_flag(0,10) + 420) <= 435))
			set_terrain(get_flag(0,8),get_flag(0,9),get_flag(0,10) + 420);
		if(((get_flag(0,13) + 420) >= 421) && ((get_flag(0,13) + 420) <= 435))
			set_terrain(get_flag(0,11),get_flag(0,12),get_flag(0,13) + 420);
		force_instant_terrain_redraw();
		//increment number of passages found
		inc_flag(11,5,1);
		set_flag(10,8,1);
	}
break;

beginstate 41; //healing pool
	if(get_flag(10,0) == 1){
		reset_dialog();
		add_dialog_str(0,"There is a small pool of clear water here. It looks refreshing, and you are thirsty.",0);
		add_dialog_choice(0,"Stay away");
		add_dialog_choice(1,"Drink the water");
		i = run_dialog(0);
		if(i == 2){
			message_dialog("Your thirst is quenched and you feel relaxed.","");
			heal_char(0,get_max_health(0)/2);
			set_flag(10,0,2);
			//increment total number of pools drunk
			i = (1 + -2 * (get_flag(11,13) > 128)) * (get_flag(11,12) + 256 * (get_flag(11,13) - (128 * (get_flag(11,13) > 128))));
			i = i + 1;
			set_flag(11,12,(1 + -2 * (i < 0)) *i);
			set_flag(11,13,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
		}
	}
	else{
		print_str_color("The water in this pool is pretty much gone.",2);
	}
break;

beginstate 42; //energizing pool
	if(get_flag(10,1) == 1){
		reset_dialog();
		add_dialog_str(0,"There is a small pool of clear water here. It looks refreshing, and you are thirsty.",0);
		add_dialog_choice(0,"Stay away");
		add_dialog_choice(1,"Drink the water");
		i = run_dialog(0);
		if(i == 2){
			message_dialog("Your thirst is quenched and you feel more energetic.","");
			change_char_energy(0,get_stat(0,36));
			set_flag(10,1,2);
			//increment total number of pools drunk
			i = (1 + -2 * (get_flag(11,13) > 128)) * (get_flag(11,12) + 256 * (get_flag(11,13) - (128 * (get_flag(11,13) > 128))));
			i = i + 1;
			set_flag(11,12,(1 + -2 * (i < 0)) *i);
			set_flag(11,13,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
		}
	}
	else{
		print_str_color("The water in this pool is pretty much gone.",2);
	}
break;

beginstate 43; //confusing pool
	if(get_flag(10,2) == 1){
		reset_dialog();
		add_dialog_str(0,"There is a small pool of clear water here. It looks refreshing, and you are thirsty.",0);
		add_dialog_choice(0,"Stay away");
		add_dialog_choice(1,"Drink the water");
		i = run_dialog(0);
		if(i == 2){
			message_dialog("Your drink the water, but begin to feel oddly dizzy.","");
			set_char_status(0,13,8,0,0);
			set_char_status(0,18,16,0,0);
			set_flag(10,2,2);
			//increment total number of pools drunk
			i = (1 + -2 * (get_flag(11,13) > 128)) * (get_flag(11,12) + 256 * (get_flag(11,13) - (128 * (get_flag(11,13) > 128))));
			i = i + 1;
			set_flag(11,12,(1 + -2 * (i < 0)) *i);
			set_flag(11,13,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
		}
	}
	else{
		print_str_color("The water in this pool is pretty much gone.",2);
	}
break;

beginstate 44; //enfeebling pool
	if(get_flag(10,3) == 1){
		reset_dialog();
		add_dialog_str(0,"There is a small pool of clear water here. It looks refreshing, and you are thirsty.",0);
		add_dialog_choice(0,"Stay away");
		add_dialog_choice(1,"Drink the water");
		i = run_dialog(0);
		if(i == 2){
			message_dialog("Your drink the water, but begin to feel very weak.","");
			set_char_status(0,3,-8,0,0);
			set_char_status(0,21,16,0,0);
			set_flag(10,3,2);
			//increment total number of pools drunk
			i = (1 + -2 * (get_flag(11,13) > 128)) * (get_flag(11,12) + 256 * (get_flag(11,13) - (128 * (get_flag(11,13) > 128))));
			i = i + 1;
			set_flag(11,12,(1 + -2 * (i < 0)) *i);
			set_flag(11,13,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
		}
	}
	else{
		print_str_color("The water in this pool is pretty much gone.",2);
	}
break;

beginstate 45; //paralysis trap
	if(get_flag(10,4) == 1){
		message_dialog("You take a step and suddenly an odd feeling comes over your entire body.","");
		set_char_status(0,11,20,0,0);
		set_char_status(0,2,-16,0,0);
		set_flag(10,4,2);
		//increment total number of traps triggered
		i = (1 + -2 * (get_flag(11,3) > 128)) * (get_flag(11,2) + 256 * (get_flag(11,3) - (128 * (get_flag(11,3) > 128))));
		i = i + 1;
		set_flag(11,2,(1 + -2 * (i < 0)) *i);
		set_flag(11,3,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
	}
break;

beginstate 46; //dumbfounding trap
	if(get_flag(10,5) == 1){
		message_dialog("You take a step and suddenly your mind feels stuffy and clumsy.","");
		set_char_status(0,13,20,0,0);
		set_char_status(0,1,-16,0,0);
		set_flag(10,5,2);
		//increment total number of traps triggered
		i = (1 + -2 * (get_flag(11,3) > 128)) * (get_flag(11,2) + 256 * (get_flag(11,3) - (128 * (get_flag(11,3) > 128))));
		i = i + 1;
		set_flag(11,2,(1 + -2 * (i < 0)) * i);
		set_flag(11,3,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
	}
break;

beginstate 47; //forcecage trap
	if(get_flag(10,6) == 1){
		message_dialog("You take a step and a magical cage spins around you.","");
		set_char_status(0,29,30,0,0);
		set_flag(10,6,2);
		//increment total number of traps triggered
		i = (1 + -2 * (get_flag(11,3) > 128)) * (get_flag(11,2) + 256 * (get_flag(11,3) - (128 * (get_flag(11,3) > 128))));
		i = i + 1;
		set_flag(11,2,(1 + -2 * (i < 0)) * i);
		set_flag(11,3,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
	}
break;

beginstate 48; //monster summon trap
	if(get_flag(10,7) == 1){
		i = 1; //type of monster to summon
		if(get_flag(0,3) <= 3)
			i = 195; //amber slime
		else if(get_flag(0,3) > 3 && get_flag(0,3) < 10)
			i = get_ran(1,196,198); //random slime
		else if(get_flag(0,3) < 20)
			i = 234; //ghoul
		else if(get_flag(0,3) < 30)
			i = 192; //worg
		else if(get_flag(0,3) < 40)
			i = 235; //roamer
		else if(get_flag(0,3) < 50)
			i = 169; //null bug
		else if(get_flag(0,3) < 60)
			i = 236; //gnoll
		else if(get_flag(0,3) < 70)
			i = 237; //observer
		else if(get_flag(0,3) < 80)
			i = 238; //phase spider
		else if(get_flag(0,3) < 90)
			i = 139; //hraithe
		else if(get_flag(0,3) < 100)
			i = 93; //gazer
		else if(get_flag(0,3) < 110)
			i = 239; //harpy
		else if(get_flag(0,3) <= 120)
			i = 240; //be very afraid
		k = 0;
		j = 0;
		while(j < 24){
			if(j < 7){
				x = char_loc_x(0) - 3 + j;
				y = char_loc_y(0) - 3;
			}
			else if(j<13){
				x = char_loc_x(0) + 3;
				y = char_loc_y(0) - 3+ j - 6;
			}
			else if(j<19){
				x = char_loc_x(0) + 3 - (j - 12);
				y = char_loc_y(0) + 3;
			}
			else{
				x = char_loc_x(0) - 3;
				y = char_loc_y(0) + 3 - (j - 18);
			}
			if(get_terrain(x,y) == 0 && get_floor(x,y) < 255){
				place_monster(x,y,i,0);
				j = j + 100;
				k = 1;
			}
			j = j + 1;
		}
		if(j >100)
			j = j - 101;
		while(j < 24){
			if(j < 7){
				x = char_loc_x(0) - 3 + j;
				y = char_loc_y(0) - 3;
			}
			else if(j<13){
				x = char_loc_x(0) + 3;
				y = char_loc_y(0) - 3 + j - 6;
			}
			else if(j<19){
				x = char_loc_x(0) + 3 - (j - 12);
				y = char_loc_y(0) + 3;
			}
			else{
				x = char_loc_x(0) - 3;
				y = char_loc_y(0) + 3 - (j - 18);
			}
			if(get_terrain(x,y) == 0 && get_floor(x,y) < 255){
				place_monster(x,y,i,0);
				j = j + 100;
				k = 2;
			}
			j = j + 1;
		}
		if(k==1)
			message_dialog("Suddenly a monster appears out of thin air next to you.","");
		if(k==2)
			message_dialog("Suddenly monsters appear out of thin air around you.","");
		set_flag(10,7,2);
		//increment total number of traps triggered
		i = (1 + -2 * (get_flag(11,3) > 128)) * (get_flag(11,2) + 256 * (get_flag(11,3) - (128 * (get_flag(11,3) > 128))));
		i = i + 1;
		set_flag(11,2,( 1 + -2 * (i < 0)) * i);
		set_flag(11,3,(i / (256 * (1 + -2 * (i < 0)))) + (128 * (i < 0)));
	}
break;